<?php

namespace app\store\controller;

use app\store\service\IndexService;
use app\store\service\LoginService;
use app\BaseController;
use app\Response;
use think\facade\Request;

class Index extends BaseController
{
    public function bannerList(){
        $type = Request::post("type",5);
        $page = Request::post("page",1);
        $num = Request::post("num",6);

        $data = IndexService::wxIndex($type,$page,$num);
        return $data;
    }


    public function userCode(){
        if(Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $url = Request::param("url");
            $type = Request::param("type");
            $data = IndexService::makeWxCode($url,$type);
            return $data;
        }
    }

    public function pickUpCode(){
        if(Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $id = Request::param("id");
            $data = IndexService::makeOrderPickUpCode($user_id,$id);
            return $data;
        }
    }

    public function storeList(){
        $page = Request::post("page");
        $num = Request::post("num");
        $province = Request::post("province");
        $city = Request::post("city");
        $area = Request::post("area");
        $keywords = Request::post("keywords");
        $longitude = Request::post("longitude");//暂时无用
        $latitude = Request::post("latitude");//暂时无用
        $data = IndexService::storeListService($page,$num,$province,$city,$area,$keywords,$longitude,$latitude);
        return $data;
    }

    /*** 商家入驻信息提交
    */
    public function contact(){
        $data = $this->request->post();
        try{
            $this->validate($data, 'Contact');
        }catch (\Exception $e){
            return Response::wrapError(0,$e->getMessage());
        }
        $res = IndexService::contactAddService($data);
        return $res;
    }

}